import { GetTableData } from "@/api/common";
import { requestUrl } from "@/api/request";
import { reactive } from "@vue/composition-api";

export function tableLoadData() {
  const tableJson = reactive({
    item: [],
    total: 0
  });
  const LoadData = (params) => {
    let requestJson = params;
    let requestData = {
      url: requestUrl[requestJson.url],
      method: requestJson.method,
      data: requestJson.data
    };
    GetTableData(requestData).then((res) => {
      let resData = res.data.data.data;
      // 更新数据
      tableJson.item = resData;
      tableJson.total = resData.length === 0 ? 0 : res.data.data.total;
    }).catch((error) => {
      console.log(error);
    });
  };
  return {
    tableJson,
    LoadData
  };
}
